﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ManagerMachine.Converter
{
    public class ConvertDataLogin
    {
        public object[] GetData(object[] param)
        {
            object[] tmp = new object[param.Length - 1];
            for (int i = 1; i < param.Length; i++)
            {
                tmp[i - 1] = param[i];
            }
            return tmp;
        }        
        public void ConvertReceive_L_CreateTable(ref int UserCreate, ref int IDTable, object[] param)
        {
            byte[] tmp = MConvert.ConvertObjectToByte(param);
            byte[] tmpUserID = new byte[4];
            byte[] tmpTableID = new byte[4];
            for (int i = 0; i < 4; i++)
            {
                tmpUserID[i] = tmp[i];
            }
            for (int i = 4; i < tmp.Length; i++)
            {
                tmpTableID[i - 4] = tmp[i];
            }           
            UserCreate = BitConverter.ToInt32(tmpUserID, 0);
            IDTable = BitConverter.ToInt32(tmpTableID, 0);
        }
        public void ConvertReceive_L_JoinTable(ref int UserJoin, ref int IDTable, object[] param)
        {
            byte[] tmp = MConvert.ConvertObjectToByte(param);
            byte[] tmpUserID = new byte[4];
            byte[] tmpTableID = new byte[4];
            for (int i = 0; i < 4; i++)
            {
                tmpUserID[i] = tmp[i];
            }
            for (int i = 4; i < 8; i++)
            {
                tmpTableID[i - 4] = tmp[i];
            }
            UserJoin = BitConverter.ToInt32(tmpUserID, 0);
            IDTable = BitConverter.ToInt32(tmpTableID, 0);
        }
        public void ConvertReceive_L_Remove_Table(ref int IDTable, object[] param)
        {
            byte[] tmp = MConvert.ConvertObjectToByte(param);         
            byte[] tmpTableID = new byte[4];            
            for (int i = 0; i < tmp.Length; i++)
            {
                tmpTableID[i] = tmp[i];
            }            
            IDTable = BitConverter.ToInt32(tmpTableID, 0);
        }

        internal void ConvertReceive_L_CreateRoom(ref int UserID, ref int RoomID, ref string RoomName, object[] param)
        {
            byte[] tmp = MConvert.ConvertObjectToByte(param);
            UserID = BitConverter.ToInt32(tmp, 0);
            RoomID = BitConverter.ToInt32(tmp, 4);
            string[] r = Encoding.UTF8.GetString(tmp, 0, tmp.Length).Substring(12).Split(":".ToCharArray());
            RoomName = r[0];
        }

        internal void ConvertReceive_L_JoinRoom(ref int UserIDJoin, ref int RoomID, object[] param)
        {
            byte[] tmp = MConvert.ConvertObjectToByte(param);
            UserIDJoin = BitConverter.ToInt32(tmp, 0);
            RoomID = BitConverter.ToInt32(tmp, 4);
        }
    }
}
